﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HelloLLLLL.Blog.Models;
using HelloLLLLL.Blog.DAL;

namespace HelloLLLLL.Blog.html
{
    public partial class Record : System.Web.UI.Page
    {
        DBHelper helper = new DBHelper();

        public List<string[]> ListTime=new List<string[]>();

        public Dictionary<string, List<LLArticle>> Dic = new Dictionary<string, List<LLArticle>>();

        protected void Page_Load(object sender, EventArgs e)
        {
            GetReocrod();
        }

        private void GetReocrod()
        {
            string sql = @"select distinct(str(year(artTime))+str(month(artTime))) as tt  from LLArticle  order by tt desc  ";

            var dt = helper.GetDataTable(sql, null);

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var ss = dt.Rows[i][0].ToString().Split(new char[1] { ' '},StringSplitOptions.RemoveEmptyEntries);



                    string[] strArr = new string[3];

                    strArr[0] = ss[0] + ss[1];

                    strArr[1] = ss[0] + "年" + ss[1] + "月";

                    strArr[2] = ss[0] + " " + ss[1];

                    ListTime.Add(strArr);
                }
            }

            if(ListTime!=null&&ListTime.Count>0)
            {
                string sql2 = @"select * from LLArticle  order by Id desc  ";

                var list = new ModelHandler<LLArticle>().FillModel(helper.GetDataTable(sql2,null));

                for (int i = 0; i < ListTime.Count; i++)
                {
                    string str = ListTime[i][2];

                    var strArr = str.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    int year = int.Parse(strArr[0]);
                    int month = int.Parse(strArr[1]);



                    var tempList = list.Where(art => art.ArtTime.Year == year && art.ArtTime.Month == month).ToList();                   
                    Dic.Add(str, tempList);
                 
                }


            }

        }
    }
}